package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetMealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{setmealId},#{checkgroupId})")
    boolean addSetMealIdAndCheckGroupId(@Param("setmealId") Integer setmealId, @Param("checkgroupId") Integer checkgroupId);

    @Select("SELECT t.name\n" +
            "FROM t_checkgroup_checkitem tcc,t_checkitem t\n" +
            "WHERE tcc.checkitem_id=t.id\n" +
            "AND tcc.checkgroup_id=#{id}")
    List<CheckItem> findCheckItemsByGroupId(@Param("id") int id);

    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID=#{setmealDTOId}")
    boolean deleteCheckGroupIdsBySetMealId(@Param("setmealDTOId") Integer setmealDTOId);

    @Select("SELECT img,NAME,remark,sex,age FROM t_setmeal where id=#{id}")
    SetmealVO selectSetMealById(@Param("id") int id);

    @Select("SELECT tc.id,tc.name,tc.remark\n" +
            "FROM t_setmeal_checkgroup tsc,t_checkgroup tc\n" +
            "WHERE tsc.checkgroup_id=tc.id\n" +
            "AND tsc.setmeal_id=#{id}")
    List<CheckGroupVO> findCheckGroupsById(@Param("id") int id);

    @Select("select img,name,remark,sex,age from t_setmeal where id=#{id}")
    Setmeal findSetMailById(@Param("id") int id);
}
